
/*******************************************\
|					    |
| Header file that displays the medium	    |
| Level high scores			    |
|					    |
| Call highscore_medium () with int score.  |
|					    |
| 					    |
\*******************************************/

FILE *fp;

/* Inserts the new highscore and prints the high score list from ./highscore_list_m.txt */
int medium_score(char name[])
{
	int x, y;		/* column and row */
	char i, buffer[20];	/* Array to read file lines into */
	
	clear();

	/* Prints header for high score screen. */
	mvprintw(2, (getmaxx(stdscr)/2) - 5, "HIGH SCORES");
	mvprintw(3, (getmaxx(stdscr)/2) - 7, "LEVEL: MEDIUM");
	refresh();

	fp = fopen("./highscore_list_m.txt", "a");	/* Opens highscore list to append. */

	fprintf(fp, "%s\t\t%6d", name, score);		/* Appends new name and score to file. */

	fclose(fp);
	
	system("./enter_medium.sh");		/* Runs script that organizes highscores by score. */

	x = 1;
	y = 5;

	fp = fopen("./highscore_list_m.txt", "r");	/* Reopens file for reading. */

	while(fgets(buffer, 15, fp) != NULL)	/* Reads and prints the txt file line by line. */
	{
		y++;
		mvprintw(y, x, "%s", buffer);
	}	

	fclose(fp);


	mvprintw(23, 1, "Press ENTER to continue.");
	refresh();

	while((i = getch()) != 10) {}		/* Ends when user types ENTER */

	return 0;	
}

/* Allows user to enter initials for high score. */
/* Accepts every other input. Solution pending.  */
int highscore_medium()
{
	int initials = 0;
	char name[10];		/* Array to store user initials. */
	clear();
	mvprintw(4, 7, "Your score is %i", score);
        refresh();

	while(!initials)
	{
		mvprintw(5, 7, "Please enter your initials ( xxx): ");	/* asks for user name, 3 characters long */
		refresh();
		getstr(name);               /* User enters initials */
		if(name[3] != '\0')
		{
			mvprintw(7, 7, "Please enter 3 characters.");
			refresh();
		}
		else
			initials = 1;
	}

	medium_score(name);	/* Sends new name and score to update the high score list. */

	
	return 0;
}
